#include "bindings/bindings_data_binding.h"
#include "helpers/exception_handler.h"
#include "helpers/general.h"
#include "refs.h"
#include <cstdio>
#include <string>
#include <vector>

// #include "helpers/jni_resource.hpp"
// #include "models/jni_renderer.hpp"
// #include "rive/animation/linear_animation_instance.hpp"
// #include "rive/animation/state_machine_instance.hpp"
// #include "rive/artboard.hpp"
// #include "rive/refcnt.hpp"
// #include "rive/text/text_value_run.hpp"
#include "rive/viewmodel/runtime/viewmodel_instance_number_runtime.hpp"
#include "rive/viewmodel/runtime/viewmodel_instance_runtime.hpp"
#include "rive/viewmodel/runtime/viewmodel_runtime.hpp"

namespace ohos_rive {

/**
 * 获取 视图模型的名称
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModel_cppName
 */
napi_value ViewModelName(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model reference");
        return nullptr;
    }

    // 获取视图模型指针
    int64_t viewModelRef;
    status = napi_get_value_int64(env, args[0], &viewModelRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model reference");
        return nullptr;
    }
    auto viewModel = reinterpret_cast<rive::ViewModelRuntime *>(viewModelRef);
    if (!viewModel) {
        LOGE("Invalid view model reference");
        return nullptr;
    }

    // 获取名称并返回字符串
    std::string name = viewModel->name();
    napi_value result;
    status = napi_create_string_utf8(env, name.c_str(), name.length(), &result);
    if (status != napi_ok) {
        LOGE("Failed to create string result");
        return nullptr;
    }
    LOGI("ViewModel name: %{public}s", name.c_str());
    return result;
}

/**
 * 获取视图模型实例数量
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModel_cppInstanceCount
 */
napi_value ViewModelInstanceCount(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model reference");
        return nullptr;
    }

    int64_t viewModelRef;
    status = napi_get_value_int64(env, args[0], &viewModelRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model reference");
        return nullptr;
    }
    auto viewModel = reinterpret_cast<rive::ViewModelRuntime *>(viewModelRef);
    if (!viewModel) {
        LOGE("Invalid view model reference");
        return nullptr;
    }

    // 获取实例数量并返回
    int count = static_cast<int>(viewModel->instanceCount());
    napi_value result;
    status = napi_create_int32(env, count, &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("ViewModel instance count: %{public}d", count);
    return result;
}

/**
 * 获取获取视图模型属性数量
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModel_cppPropertyCount
 */
napi_value ViewModelPropertyCount(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model reference");
        return nullptr;
    }

    int64_t viewModelRef;
    status = napi_get_value_int64(env, args[0], &viewModelRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model reference");
        return nullptr;
    }
    auto viewModel = reinterpret_cast<rive::ViewModelRuntime *>(viewModelRef);
    if (!viewModel) {
        LOGE("Invalid view model reference");
        return nullptr;
    }

    // 获取属性数量并返回
    int count = static_cast<int>(viewModel->propertyCount());

    napi_value result;
    status = napi_create_int32(env, count, &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("ViewModel property count: %{public}d", count);
    return result;
}

// Java_app_rive_runtime_kotlin_core_ViewModel_cppGetProperties
napi_value ViewModelGetProperties(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model reference");
        return nullptr;
    }

    int64_t viewModelRef;
    status = napi_get_value_int64(env, args[0], &viewModelRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model reference");
        return nullptr;
    }
    auto viewModel = reinterpret_cast<rive::ViewModelRuntime *>(viewModelRef);
    if (!viewModel) {
        LOGE("Invalid view model reference");
        return nullptr;
    }
    // 获取属性
    auto properties = viewModel->properties();

    // 创建空数组
    napi_value array;
    status = napi_create_array(env, &array);
    if (status != napi_ok) {
        LOGE("Failed to create array");
        return nullptr;
    }
    napi_value cls = FindClass(env, "PropertyData").get();
    napi_value cls2 = FindClass(env, "PropertyDataUtils").get();

    size_t index = 0;
    for (const auto &property : properties) {
        LOGI("ViewModelGetProperties property name: %{public}s, property type = %{public}d", property.name.c_str(),
             property.type);
        auto name = MakeNapiString(env, property.name);

        napi_value propertyType;
        napi_create_int32(env, (int)property.type, &propertyType);
        napi_value *argv = &propertyType;
        napi_value methodId2 = GetStaticMethodId(env, cls2, "fromIndex");
        napi_value result;
        status = napi_call_function(env, cls2, methodId2, 1, argv, &result);
        if (status != napi_ok) {
            LOGE("Failed to call function");
            return nullptr;
        }

        napi_value args[2];
        args[0] = result;
        args[1] = name.get();
        auto propertyObject = MakeObject(env, cls, 2, args);
        napi_set_element(env, array, index, propertyObject.get());
        index++;
    }
    return array;
}

/**
 * 创建空白视图模型实例
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModel_cppCreateBlankInstance
 */
napi_value ViewModelCreateBlankInstance(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model reference");
        return nullptr;
    }

    int64_t viewModelRef;
    status = napi_get_value_int64(env, args[0], &viewModelRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model reference");
        return nullptr;
    }
    auto viewModel = reinterpret_cast<rive::ViewModelRuntime *>(viewModelRef);
    if (!viewModel) {
        LOGE("Invalid view model reference");
        return nullptr;
    }

    // 创建空白实例
    auto instance = viewModel->createInstance();
    if (!instance) {
        LOGE("Failed to create view model instance");
        return nullptr;
    }

    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(instance.release()), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    return result;
}

/**
 * 创建默认视图模型实例
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModel_cppCreateDefaultInstance
 */
napi_value ViewModelCreateDefaultInstance(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model reference");
        return nullptr;
    }
    int64_t viewModelRef;
    status = napi_get_value_int64(env, args[0], &viewModelRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model reference");
        return nullptr;
    }
    auto viewModel = reinterpret_cast<rive::ViewModelRuntime *>(viewModelRef);
    if (!viewModel) {
        LOGE("Invalid view model reference");
        return nullptr;
    }

    // 创建默认实例
    auto instance = viewModel->createDefaultInstance();
    if (!instance) {
        LOGE("Failed to create default view model instance");
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(instance.release()), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    return result;
}

/**
 * 通过索引创建视图模型实例
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModel_cppCreateInstanceFromIndex
 */
napi_value ViewModelCreateInstanceFromIndex(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model reference and index");
        return nullptr;
    }
    int64_t viewModelRef;
    status = napi_get_value_int64(env, args[0], &viewModelRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model reference");
        return nullptr;
    }
    int32_t index;
    status = napi_get_value_int32(env, args[1], &index);
    if (status != napi_ok) {
        LOGE("Failed to get instance index");
        return nullptr;
    }
    auto viewModel = reinterpret_cast<rive::ViewModelRuntime *>(viewModelRef);
    if (!viewModel) {
        LOGE("Invalid view model reference");
        return nullptr;
    }
    // 通过索引创建实例
    auto instance = viewModel->createInstanceFromIndex(static_cast<size_t>(index));
    if (!instance) {
        LOGE("Failed to create view model instance from index: %{public}d", index);
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(instance.release()), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model instance created from index: %{public}d", index);
    return result;
}

/**
 * 通过名称创建视图模型实例
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModel_cppCreateInstanceFromName
 */
napi_value ViewModelCreateInstanceFromName(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model reference and name");
        return nullptr;
    }
    int64_t viewModelRef;
    status = napi_get_value_int64(env, args[0], &viewModelRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model reference");
        return nullptr;
    }
    // 获取名称字符串
    std::string instanceName = NapiStringToString(env, args[1]);
    auto viewModel = reinterpret_cast<rive::ViewModelRuntime *>(viewModelRef);
    if (!viewModel) {
        LOGE("Invalid view model reference");
        return nullptr;
    }
    // 通过名称创建实例
    auto instance = viewModel->createInstanceFromName(instanceName);
    if (!instance) {
        LOGE("Failed to create view model instance from name: %{public}s", instanceName.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(instance.release()), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model instance created from name: %{public}s", instanceName.c_str());
    return result;
}

/**
 * 获取视图模型实例名称
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppName
 */
napi_value ViewModelInstanceName(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model instance reference");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 获取名称并返回字符串
    std::string name = viewModelInstance->name();
    napi_value result;
    status = napi_create_string_utf8(env, name.c_str(), name.length(), &result);
    if (status != napi_ok) {
        LOGE("Failed to create string result");
        return nullptr;
    }
    LOGI("View model instance name: %{public}s", name.c_str());
    return result;
}

/**
 * 通过路径获取属性编号
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyNumber
 */
napi_value ViewModelInstancePropertyNumber(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 通过路径获取属性编号
    auto propertyNumber = viewModelInstance->propertyNumber(propertyPath);

    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyNumber), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model instance property number: %{public}d", propertyNumber->dataType());
    return result;
}

/**
 * 通过路径获取字符串属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyString
 */
napi_value ViewModelInstancePropertyString(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];

    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 通过路径获取字符串属性
    auto propertyString = viewModelInstance->propertyString(propertyPath);
    if (!propertyString) {
        LOGE("String property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyString), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model instance property string: %{public}d", propertyString->dataType());
    return result;
}

/**
 * 通过路径获取布尔属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyBoolean
 */
napi_value ViewModelInstancePropertyBoolean(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }

    // 通过路径获取布尔属性
    auto propertyBoolean = viewModelInstance->propertyBoolean(propertyPath);
    if (!propertyBoolean) {
        LOGE("Boolean property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyBoolean), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("Boolean property found for path: %{public}s", propertyPath.c_str());
    return result;
}

/**
 * 通过路径获取颜色属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyColor
 */
napi_value ViewModelInstancePropertyColor(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }

    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }

    // 通过路径获取颜色属性
    auto propertyColor = viewModelInstance->propertyColor(propertyPath);
    if (!propertyColor) {
        LOGE("Color property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyColor), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("Color property found for path: %{public}s", propertyPath.c_str());
    return result;
}

/**
 * 通过路径获取枚举属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyEnum
 */
napi_value ViewModelInstancePropertyEnum(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }

    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }

    // 通过路径获取枚举属性
    auto propertyEnum = viewModelInstance->propertyEnum(propertyPath);
    if (!propertyEnum) {
        LOGE("Enum property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyEnum), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("Enum property found for path: %{public}s", propertyPath.c_str());
    return result;
}

/**
 * 通过路径获取触发器属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyTrigger
 */
napi_value ViewModelInstancePropertyTrigger(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 通过路径获取触发器属性
    auto propertyTrigger = viewModelInstance->propertyTrigger(propertyPath);
    if (!propertyTrigger) {
        LOGE("Trigger property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyTrigger), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("Trigger property found for path: %{public}s", propertyPath.c_str());
    return result;
}

/**
 * 通过路径获取图片属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyImage
 */
napi_value ViewModelInstancePropertyImage(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 通过路径获取图像属性
    auto propertyImage = viewModelInstance->propertyImage(propertyPath);
    if (!propertyImage) {
        LOGE("Image property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyImage), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("Image property found for path: %{public}s", propertyPath.c_str());
    return result;
}

/**
 * 通过路径获取列表属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyList
 */
napi_value ViewModelInstancePropertyList(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 通过路径获取列表属性
    auto propertyList = viewModelInstance->propertyList(propertyPath);
    if (!propertyList) {
        LOGE("List property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyList), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("List property found for path: %{public}s", propertyPath.c_str());
    return result;
}

/**
 * 通过路径获取Artboard属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyArtboard
 */
napi_value ViewModelInstancePropertyArtboard(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 通过路径获取Artboard属性
    auto propertyArtboard = viewModelInstance->propertyArtboard(propertyPath);
    if (!propertyArtboard) {
        LOGE("Artboard property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyArtboard), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("Artboard property found for path: %{public}s", propertyPath.c_str());
    return result;
}

/**
 * 通过路径获取视图模型实例属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppPropertyInstance
 */
napi_value ViewModelInstancePropertyInstance(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model instance reference and path");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 通过路径获取视图模型实例属性
    auto propertyInstance = viewModelInstance->propertyViewModel(propertyPath);
    if (!propertyInstance) {
        LOGE("View model instance property not found for path: %{public}s", propertyPath.c_str());
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(propertyInstance.release()), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model instance property found for path: %{public}s", propertyPath.c_str());
    return result;
}

/**
 * 设置视图模型实例属性
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppSetInstanceProperty
 */
napi_value ViewModelInstanceSetInstanceProperty(napi_env env, napi_callback_info info)
{
    size_t argc = 3;
    napi_value args[3];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 3) {
        LOGE("Invalid arguments - expected view model instance reference, path and property reference");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    // 获取路径字符串
    std::string propertyPath = NapiStringToString(env, args[1]);
    // 获取属性实例指针
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[2], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get property instance reference");
        return nullptr;
    }
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    auto propertyInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(propertyRef);
    if (!propertyInstance) {
        LOGE("Invalid property instance reference");
        return nullptr;
    }

    // 设置视图模型实例属性
    bool result = viewModelInstance->replaceViewModel(propertyPath, propertyInstance);

    // 返回布尔结果
    napi_value jsResult;
    status = napi_get_boolean(env, result, &jsResult);
    if (status != napi_ok) {
        LOGE("Failed to create boolean result");
        return nullptr;
    }
    return jsResult;
}

/**
 * 增加视图模型实例引用计数
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppRefInstance
 */
napi_value ViewModelInstanceRefInstance(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model instance reference");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }

    // 增加引用计数
    viewModelInstance->ref();
    LOGI("View model instance reference count increased");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

/**
 * 减少视图模型实例引用计数
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelInstance_cppDerefInstance
 */
napi_value ViewModelInstanceDerefInstance(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model instance reference");
        return nullptr;
    }
    int64_t viewModelInstanceRef;
    status = napi_get_value_int64(env, args[0], &viewModelInstanceRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model instance reference");
        return nullptr;
    }
    auto viewModelInstance = reinterpret_cast<rive::ViewModelInstanceRuntime *>(viewModelInstanceRef);
    if (!viewModelInstance) {
        LOGE("Invalid view model instance reference");
        return nullptr;
    }
    // 减少引用计数
    viewModelInstance->unref();
    LOGI("View model instance reference count decreased");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

/**
 * 获取视图模型属性名称
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelProperty_cppName
 */
napi_value ViewModelPropertyName(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceValueRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model property reference");
        return nullptr;
    }

    // 获取名称并返回字符串
    std::string name = property->name();
    napi_value result;
    status = napi_create_string_utf8(env, name.c_str(), name.length(), &result);
    if (status != napi_ok) {
        LOGE("Failed to create string result");
        return nullptr;
    }
    LOGI("View model property name: %{public}s", name.c_str());
    return result;
}

/**
 * 检查视图模型属性是否已更改
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelProperty_cppHasChanged
 */
napi_value ViewModelPropertyHasChanged(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceValueRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model property reference");
        return nullptr;
    }

    // 检查属性是否已更改
    bool hasChanged = property->hasChanged();
    napi_value result;
    status = napi_get_boolean(env, hasChanged, &result);
    if (status != napi_ok) {
        LOGE("Failed to create boolean result");
        return nullptr;
    }
    LOGI("View model property changed status: %{public}s", hasChanged ? "true" : "false");
    return result;
}

/**
 * 刷新视图模型属性更改
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelProperty_cppFlushChanges
 */
napi_value ViewModelPropertyFlushChanges(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceValueRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model property reference");
        return nullptr;
    }
    // 刷新属性更改
    bool result = property->flushChanges();
    napi_value jsResult;
    status = napi_get_boolean(env, result, &jsResult);
    if (status != napi_ok) {
        LOGE("Failed to create boolean result");
        return nullptr;
    }
    LOGI("View model property flush changes %{public}s", result ? "successful" : "failed");
    return jsResult;
}

/**
 * 获取数值属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelNumberProperty_cppGetValue
 */
napi_value ViewModelNumberPropertyGetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model number property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model number property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceNumberRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model number property reference");
        return nullptr;
    }
    // 获取数值并返回
    float value = property->value();
    napi_value result;
    status = napi_create_double(env, value, &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model number property value: %{public}f", value);
    return result;
}

/**
 * 设置数值属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelNumberProperty_cppSetValue
 */
napi_value ViewModelNumberPropertySetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model number property reference and value");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model number property reference");
        return nullptr;
    }
    // 获取数值
    double value;
    status = napi_get_value_double(env, args[1], &value);
    if (status != napi_ok) {
        LOGE("Failed to get value");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceNumberRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model number property reference");
        return nullptr;
    }
    // 设置数值
    property->value(static_cast<float>(value));
    LOGI("View model number property value set to: %{public}f", value);
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

/**
 * 获取字符串属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelStringProperty_cppGetValue
 */
napi_value ViewModelStringPropertyGetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model string property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model string property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceStringRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model string property reference");
        return nullptr;
    }

    // 获取字符串值并返回
    std::string value = property->value();
    napi_value result;
    status = napi_create_string_utf8(env, value.c_str(), value.length(), &result);
    if (status != napi_ok) {
        LOGE("Failed to create string result");
        return nullptr;
    }
    LOGI("View model string property value: %{public}s", value.c_str());
    return result;
}

/**
 * 设置字符串属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelStringProperty_cppSetValue
 */
napi_value ViewModelStringPropertySetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model string property reference and value");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model string property reference");
        return nullptr;
    }
    // 获取字符串值
    std::string stringValue = NapiStringToString(env, args[1]);
    auto property = reinterpret_cast<rive::ViewModelInstanceStringRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model string property reference");
        return nullptr;
    }
    // 设置字符串值
    property->value(stringValue);
    LOGI("View model string property value set to: %{public}s", stringValue.c_str());
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

/**
 * 获取布尔属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelBooleanProperty_cppGetValue
 */
napi_value ViewModelBooleanPropertyGetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model boolean property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model boolean property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceBooleanRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model boolean property reference");
        return nullptr;
    }
    // 获取布尔值并返回
    bool value = property->value();

    napi_value result;
    status = napi_get_boolean(env, value, &result);
    if (status != napi_ok) {
        LOGE("Failed to create boolean result");
        return nullptr;
    }
    LOGI("View model boolean property value: %{public}s", value ? "true" : "false");
    return result;
}

/**
 * 设置布尔属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelBooleanProperty_cppSetValue
 */
napi_value ViewModelBooleanPropertySetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model boolean property reference and value");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model boolean property reference");
        return nullptr;
    }
    // 获取布尔值
    bool value;
    status = napi_get_value_bool(env, args[1], &value);
    if (status != napi_ok) {
        LOGE("Failed to get boolean value");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceBooleanRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model boolean property reference");
        return nullptr;
    }
    // 设置布尔值
    property->value(value);
    LOGI("View model boolean property value set to: %{public}s", value ? "true" : "false");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

/**
 * 获取颜色属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelColorProperty_cppGetValue
 */
napi_value ViewModelColorPropertyGetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model color property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model color property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceColorRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model color property reference");
        return nullptr;
    }
    // 获取颜色值并返回
    int value = property->value();
    napi_value result;
    status = napi_create_int32(env, value, &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model color property value: 0x%{public}X", value);
    return result;
}

/**
 * 设置颜色属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelColorProperty_cppSetValue
 */
napi_value ViewModelColorPropertySetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model color property reference and value");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model color property reference");
        return nullptr;
    }
    // 获取颜色值
    int32_t value;
    status = napi_get_value_int32(env, args[1], &value);
    if (status != napi_ok) {
        LOGE("Failed to get color value");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceColorRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model color property reference");
        return nullptr;
    }
    // 设置颜色值
    property->value(value);
    LOGI("View model color property value set to: 0x%{public}X", value);
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

/**
 * 获取枚举属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelEnumProperty_cppGetValue
 */
napi_value ViewModelEnumPropertyGetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model enum property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model enum property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceEnumRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model enum property reference");
        return nullptr;
    }

    // 获取枚举值并返回字符串
    std::string value = property->value();
    napi_value result;
    status = napi_create_string_utf8(env, value.c_str(), value.length(), &result);
    if (status != napi_ok) {
        LOGE("Failed to create string result");
        return nullptr;
    }
    LOGI("View model enum property value: %{public}s", value.c_str());
    return result;
}

/**
 * 设置枚举属性值
 * 对应原 JNI Java_app_rive_runtime_kotlin_core_ViewModelEnumProperty_cppSetValue
 */
napi_value ViewModelEnumPropertySetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model enum property reference and value");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model enum property reference");
        return nullptr;
    }

    // 获取枚举值字符串
    std::string enumValue = NapiStringToString(env, args[1]);
    auto property = reinterpret_cast<rive::ViewModelInstanceEnumRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model enum property reference");
        return nullptr;
    }
    // 设置枚举值
    property->value(enumValue);
    LOGI("View model enum property value set to: %{public}s", enumValue.c_str());
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelTriggerPropertyTrigger(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model trigger property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model trigger property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceTriggerRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model trigger property reference");
        return nullptr;
    }
    // 触发触发器
    property->trigger();
    LOGI("View model trigger property triggered");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelImagePropertySetValue(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model image property reference and image reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model image property reference");
        return nullptr;
    }

    // 获取图像指针
    int64_t imageRef;
    status = napi_get_value_int64(env, args[1], &imageRef);
    if (status != napi_ok) {
        LOGE("Failed to get image reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceAssetImageRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model image property reference");
        return nullptr;
    }
    auto image = reinterpret_cast<rive::RenderImage *>(imageRef);
    if (!image) {
        LOGE("Invalid image reference");
        return nullptr;
    }

    // 设置图像值
    property->value(image);
    LOGI("View model image property value set successfully");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelListPropertySize(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 1) {
        LOGE("Invalid arguments - expected view model list property reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model list property reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceListRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model list property reference");
        return nullptr;
    }
    // 获取列表大小并返回
    int size = static_cast<int>(property->size());
    napi_value result;
    status = napi_create_int32(env, size, &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model list property size: %{public}d", size);
    return result;
}

napi_value ViewModelListPropertyElementAt(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model list property reference and index");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model list property reference");
        return nullptr;
    }
    int32_t index;
    status = napi_get_value_int32(env, args[1], &index);
    if (status != napi_ok) {
        LOGE("Failed to get element index");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceListRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model list property reference");
        return nullptr;
    }

    // 通过索引获取元素
    auto element = property->instanceAt(index);
    if (!element) {
        LOGE("Element not found at index: %{public}d", index);
        return nullptr;
    }
    napi_value result;
    status = napi_create_int64(env, reinterpret_cast<int64_t>(element.release()), &result);
    if (status != napi_ok) {
        LOGE("Failed to create result");
        return nullptr;
    }
    LOGI("View model list element found at index: %{public}d", index);
    return result;
}

napi_value ViewModelListPropertyAdd(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model list property reference and item reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model list property reference");
        return nullptr;
    }
    int64_t itemRef;
    status = napi_get_value_int64(env, args[1], &itemRef);
    if (status != napi_ok) {
        LOGE("Failed to get item reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceListRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model list property reference");
        return nullptr;
    }
    auto item = reinterpret_cast<rive::ViewModelInstanceRuntime *>(itemRef);
    if (!item) {
        LOGE("Invalid item reference");
        return nullptr;
    }
    // 向列表添加元素
    property->addInstance(item);
    LOGI("Item added to view model list property successfully");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelListPropertyAddAt(napi_env env, napi_callback_info info)
{
    size_t argc = 3;
    napi_value args[3];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 3) {
        LOGE("Invalid arguments - expected view model list property reference, index and item reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model list property reference");
        return nullptr;
    }
    // 获取索引
    int32_t index;
    status = napi_get_value_int32(env, args[1], &index);
    if (status != napi_ok) {
        LOGE("Failed to get index");
        return nullptr;
    }
    int64_t itemRef;
    status = napi_get_value_int64(env, args[2], &itemRef);
    if (status != napi_ok) {
        LOGE("Failed to get item reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceListRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model list property reference");
        return nullptr;
    }
    auto item = reinterpret_cast<rive::ViewModelInstanceRuntime *>(itemRef);
    if (!item) {
        LOGE("Invalid item reference");
        return nullptr;
    }
    // 在指定位置向列表添加元素
    property->addInstanceAt(item, index);
    LOGI("Item added to view model list property at index: %{public}d", index);
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelListPropertyRemove(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model list property reference and item reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model list property reference");
        return nullptr;
    }
    int64_t itemRef;
    status = napi_get_value_int64(env, args[1], &itemRef);
    if (status != napi_ok) {
        LOGE("Failed to get item reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceListRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model list property reference");
        return nullptr;
    }
    auto item = reinterpret_cast<rive::ViewModelInstanceRuntime *>(itemRef);
    if (!item) {
        LOGE("Invalid item reference");
        return nullptr;
    }
    // 从列表中移除元素
    property->removeInstance(item);
    LOGI("Item removed from view model list property successfully");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelListPropertyRemoveAt(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model list property reference and index");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model list property reference");
        return nullptr;
    }
    int32_t index;
    status = napi_get_value_int32(env, args[1], &index);
    if (status != napi_ok) {
        LOGE("Failed to get index");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceListRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model list property reference");
        return nullptr;
    }
    // 从指定位置移除元素
    property->removeInstanceAt(index);
    LOGI("Item removed from view model list property at index: %{public}d", index);
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelListPropertySwap(napi_env env, napi_callback_info info)
{
    size_t argc = 3;
    napi_value args[3];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 3) {
        LOGE("Invalid arguments - expected view model list property reference and two indices");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model list property reference");
        return nullptr;
    }
    int32_t indexA;
    status = napi_get_value_int32(env, args[1], &indexA);
    if (status != napi_ok) {
        LOGE("Failed to get first index");
        return nullptr;
    }
    int32_t indexB;
    status = napi_get_value_int32(env, args[2], &indexB);
    if (status != napi_ok) {
        LOGE("Failed to get second index");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceListRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model list property reference");
        return nullptr;
    }
    // 交换两个位置的元素
    property->swap(indexA, indexB);
    LOGI("Items swapped at indices: %{public}d and %{public}d", indexA, indexB);
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelArtboardPropertySetArtboard(napi_env env, napi_callback_info info)
{
    size_t argc = 3;
    napi_value args[3];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 3) {
        LOGE(
            "Invalid arguments - expected view model artboard property reference, file reference and artboard "
            "reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model artboard property reference");
        return nullptr;
    }
    int64_t fileRef;
    status = napi_get_value_int64(env, args[1], &fileRef);
    if (status != napi_ok) {
        LOGE("Failed to get file reference");
        return nullptr;
    }
    // 获取Artboard指针
    int64_t artboardRef;
    status = napi_get_value_int64(env, args[2], &artboardRef);
    if (status != napi_ok) {
        LOGE("Failed to get artboard reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceArtboardRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model artboard property reference");
        return nullptr;
    }
    auto file = reinterpret_cast<rive::File *>(fileRef);
    if (!file) {
        LOGE("Invalid file reference");
        return nullptr;
    }
    auto artboard = reinterpret_cast<rive::Artboard *>(artboardRef);
    if (!artboard) {
        LOGE("Invalid artboard reference");
        return nullptr;
    }
    // 获取可绑定的Artboard并设置属性值
    auto bindableArtboard = file->internalBindableArtboardFromArtboard(artboard);
    property->value(bindableArtboard);
    LOGI("View model artboard property value set successfully");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}

napi_value ViewModelArtboardPropertySetBindableArtboard(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[2];
    napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    if (status != napi_ok || argc < 2) {
        LOGE("Invalid arguments - expected view model artboard property reference and bindable artboard reference");
        return nullptr;
    }
    int64_t propertyRef;
    status = napi_get_value_int64(env, args[0], &propertyRef);
    if (status != napi_ok) {
        LOGE("Failed to get view model artboard property reference");
        return nullptr;
    }
    int64_t bindableArtboardRef;
    status = napi_get_value_int64(env, args[1], &bindableArtboardRef);
    if (status != napi_ok) {
        LOGE("Failed to get bindable artboard reference");
        return nullptr;
    }
    auto property = reinterpret_cast<rive::ViewModelInstanceArtboardRuntime *>(propertyRef);
    if (!property) {
        LOGE("Invalid view model artboard property reference");
        return nullptr;
    }
    auto bindableArtboard = reinterpret_cast<rive::BindableArtboard *>(bindableArtboardRef);
    if (!bindableArtboard) {
        LOGE("Invalid bindable artboard reference");
        return nullptr;
    }
    auto rcpBindableArtboard = rive::rcp(bindableArtboard);
    property->value(rcpBindableArtboard);

    // 释放rcp引用，避免超出作用域时解除引用
    rcpBindableArtboard.release();
    LOGI("View model bindable artboard property value set successfully");
    // 返回undefined（void方法）
    napi_value undefined;
    napi_get_undefined(env, &undefined);
    return undefined;
}
} // namespace ohos_rive